//
//  FMTableViewCell.m
//  XWZ_News_Work
//
//  Created by dllo on 16/1/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FMTableViewCell.h"
#import "FMMainCollectionViewCell.h"
#import "tListRadioModel.h"

@interface FMTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionV;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;

@end

@implementation FMTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.layout.itemSize = CGSizeMake((SCREEN_WIDTH - 50) / 3, (SCREEN_WIDTH - 50) / 2 + 25);
    self.layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
    self.collectionV.frame = self.contentView.frame;
}

- (void)setArr:(NSMutableArray *)arr
{
    _arr = arr;
    [self.collectionV reloadData];
}

- (void)createSubview
{
    self.backgroundColor = [UIColor blueColor];
    
    self.layout = [[UICollectionViewFlowLayout alloc] init];
    self.layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.layout.minimumLineSpacing = 1;
    self.layout.minimumInteritemSpacing = 1;
    
    self.collectionV = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.layout];
    self.collectionV.delegate = self;
    self.collectionV.dataSource = self;
    self.collectionV.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.collectionV];
    [self.collectionV registerClass:[FMMainCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    FMMainCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    tListRadioModel *model = [self.arr objectAtIndex:indexPath.row];
    cell.labelName.text = model.tname;
    cell.labelTitle.text = model.title;
    NSURL *url = [NSURL URLWithString:model.imgsrc];
    [cell.imageV sd_setImageWithURL:url];
    
    return cell;
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate returnPlayerByRow:indexPath.row index:self.index];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
